package com.jiangsong.batch.abst;

import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext;
import org.springframework.batch.core.scope.context.StepContext;
import org.springframework.util.Assert;

public class StepSyncManager {

    private static final AbstractSyncManagerSupport<StepExecution, StepContext> MANAGER = new AbstractSyncManagerSupport<StepExecution, StepContext>() {
        @Override
        protected StepContext newContext(StepExecution execution, BatchPropertyContext batchPropertyContext) {
            if (null == batchPropertyContext) {
                return new StepContext(execution);
            }
            return new StepContext(execution, batchPropertyContext);
        }
    };

    public static StepContext getContext() {
        StepContext context = MANAGER.getContext();
        Assert.notNull(context, "context不允许为空");
        return context;
    }

    public static void register(StepExecution stepExecution) {
        MANAGER.register(stepExecution);
    }

    public static void release() {
        MANAGER.release();
    }
}
